﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using Ookii.Dialogs.Wpf;
using System.Reflection;

namespace DcsGauges.Server.ViewModels
{
    class DcsA10ToolsViewModel : ViewModelBase
    {
        private string installLocation = "";
        public string InstallLocation
        {
            get { return this.installLocation; }
            set
            {
                if (this.installLocation != value)
                {
                    this.installLocation = value;
                    this.OnPropertyChanged(MethodBase.GetCurrentMethod());
                }
            }
        }

        private ICommand patchFilesCommand                 = null;
        public ICommand PatchFilesCommand
        {
            get
            {
                if (this.patchFilesCommand == null)
                    this.patchFilesCommand = new DelegateCommand<object>((o) => { this.ExecutePatchFiles(); }, (o) => {return CanExecutePatchAndUnpatch(); });
                return this.patchFilesCommand;
            }
        }

        private ICommand unpatchFilesCommand                 = null;
        public ICommand UnpatchFilesCommand
        {
            get
            {
                if (this.unpatchFilesCommand == null)
                    this.unpatchFilesCommand = new DelegateCommand<object>((o) => {}, (o) => {return CanExecutePatchAndUnpatch(); });
                return this.unpatchFilesCommand;
            }
        }

        private ICommand searchInstallLocationsCommand = null;
        public ICommand SearchInstallLocationsCommand
        {
            get
            {
                if (this.searchInstallLocationsCommand == null)
                    this.searchInstallLocationsCommand = new DelegateCommand<object>((o) => { this.SerachInstallLocations(); });
                return this.searchInstallLocationsCommand;
            }
        }

        private bool CanExecutePatchAndUnpatch()
        {
            return !string.IsNullOrWhiteSpace(this.InstallLocation);
        }

        private void ExecutePatchFiles()
        {

        }

        private void SerachInstallLocations()
        {
            VistaFolderBrowserDialog dlg = new VistaFolderBrowserDialog();
            if (dlg.ShowDialog() == true)
            {
                this.InstallLocation = dlg.SelectedPath;
            }
        }
    }
}
